<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"
    />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script src="./js/lib.js"></script>
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">演示</a>
            <a>
                <cite>导航元素</cite>
            </a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);"
            title="刷新">
            <i class="layui-icon" style="line-height:30px">ဂ</i>
        </a>
    </div>
    <div class="x-body">
        <div class="x-body">
            <form class="layui-form">
                <div class="layui-form-item">
                    <label for="L_email" class="layui-form-label">
                        用户邮箱
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="aMail" name="email" change="n"  autocomplete="off" class="layui-input" disabled="disabled">
                    </div>
                    <label for="" class="layui-form-label">
                        <span class="x-red"></span>手机号
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="aPhone" name="phone" change="y"  autocomplete="off" class="layui-input" disabled="disabled">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_username" class="layui-form-label">
                        <span class="x-red"></span>昵称
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="username" name="username" change="y" required="" lay-verify="nikename" autocomplete="off" class="layui-input" disabled="disabled">
                    </div>
                    <label for="L_pass" class="layui-form-label">
                        <span class="x-red"></span>注册时间
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="createTime" name="pass" change="n" required="" autocomplete="off" class="layui-input" disabled="disabled">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                        <span class="x-red"></span>身份
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="adminRole" name="repass" change="n" required="" autocomplete="off" class="layui-input" disabled="disabled">
                    </div>
                    <label for="L_repass" class="layui-form-label">
                        <span class="x-red"></span>上次登录IP
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="lastLoginIp" name="repass" change="n" required="" autocomplete="off" class="layui-input" disabled="disabled">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                        <span class="x-red"></span>上次登录时间
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="lastLoginTime" name="repass" change="n" required="" autocomplete="off" class="layui-input" disabled="disabled">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                    </label>
                    <a class="layui-btn" id="modifyAdminBtn">
                        修改信息
                    </a>
                    <a class="layui-btn layui-btn-normal x-dis-none" id="submitInfo" style="margin-left:0px">
                        确认修改
                    </a>
                </div>
            </form>
        </div>
        <xblock>
            <span class="x-right" style="line-height:40px">共有数据：
                <span id="dataSize">0</span> 条</span>
        </xblock>
        <table class="layui-table">
            <thead>
                <tr>
                    <th>adminID</th>
                    <th>用户名称</th>
                    <th>邮箱</th>
                    <th>登录地址</th>
                    <th>登录时间</th>
                </tr> 
            </thead>
            <tbody id="adminLoginTable">
            </tbody>
        </table>
        <div class="page">
            <div>
                <a class="prev" href="">&lt;&lt;</a>
                <span class="current" href="">1</span>
                <a class="num" href="">2</a>
                <a class="num" href="">3</a>
                <a class="next" href="">&gt;&gt;</a>
            </div>
        </div>

    </div>
   
    <script>
        $(function(event) {
            layui.use('layer', function() {
                var adminInfoStrongData = undefined;

                var layer = layui.layer;
                var aId = Cookies.get('kplus-helmetAdminId')
                var aToken = Cookies.get('kplus-helmetAdminToken')
                function getAdminInfo() { 
                    ajax({
                        'url': bAsEuRl + uRlS.admin,
                        'type': 'GET',
                        'data': {
                            'aId': aId,
                            'aToken': aToken
                        },
                        success: function (data) {
                            if (data.msg.code == 200) {
                                adminInfoStrongData = data.data;
                                var createTime = formatTime(data.data.formatTime)
                                var lastLoginTime = formatTime(data.data.lastLoginTime)
                                $('#aMail').val(data.data.aMail)    //用户邮箱
                                $('#aPhone').val(data.data.aPhone)  //用户手机号
                                $('#username').val(data.data.aName)  //用户名称
                                $('#createTime').val(createTime)     //创建时间
                                $('#adminRole').val(data.data.aRole)  //身份
                                $('#lastLoginIp').val(data.data.lastLoginIp)  //上次登录ip
                                $('#lastLoginTime').val(lastLoginTime)   //上次登录时间
                                var loginData = data.data.loginData
                                var adminLoginTable = $('#adminLoginTable');
                                for(var i = 0; i < loginData.length; i++){    //登录记录
                                    var tr = '<tr><td>'+ loginData[i].a_id +'</td>'
                                            +'<td >'+ data.data.aName+'</td>'
                                            +'<td>'+ data.data.aMail+'</td>'
                                            +'<td>'+ loginData[i].op_ip+'</td>'
                                            +'<td>'+ formatTime(loginData[i].format_time)+'</td></tr>'
                                    adminLoginTable.append(tr);
                                }
                                $('#dataSize').text(loginData.length)
                                layer.close(msgIndex);  //关闭msg
                            } else {
                                layer.close(msgIndex);  //关闭msg
                                layer.msg(data.msg.msg, {
                                    time: 2000
                                })
                            }
                        },
                        error: function (data) {
                            alert('发生严重错误！')
                        }
                    })
                }
                var msgIndex = layer.load(1, {
                    shade: [0.5, '#000']
                });
                getAdminInfo();   //获取管理员身份
                $('input[type="text"]').css({
                    'background-color':'#eee'
                })
                $('#modifyAdminBtn').on('click', function(){    //点击修改管理员信息
                    $('input[change="y"]').removeAttr('disabled').css({
                        'background-color': '#fff'
                    })
                    $(this).addClass('x-dis-none');
                    $('#submitInfo').removeClass('x-dis-none');
                })
                $('#submitInfo').on('click', function () {  //确认修改
                    var aPhone = $('#aPhone').val()  //用户手机号
                    var username = $('#username').val()  //用户名称
                    var data = {
                        'aId': aId,
                        'aToken': aToken,
                        'spmId': aId
                    }
                    if(username != adminInfoStrongData.aName){
                        data['aName'] = username
                    }
                    if(aPhone != adminInfoStrongData.aPhone){
                        data['aPhone'] = aPhone
                    }
                    var msgIndex2 = layer.load(1, {
                        shade: [0.5, '#000']
                    }); 
                    $.ajax({
                        'url':'http://127.0.0.1:8080/api/v3/a/a',
                        'type': 'DELETE',
                        'data': data,
                        success: function (data) {
                            if (data.msg.code == 200) {
                                layer.close(msgIndex);  //关闭msg
                                location.reload();
                            }
                        },
                        error: function (data) { 
                            alert('发生严重错误，系统退出')
                            location.reload();
                         }
                    })  

                })
            }) 
        })
    </script>



</body>

</html>